package utils.response;

import java.io.File;
import utils.request.Request;
import severdorhttpsimples.*;

public class ResponseFactory {

    public static Response createResponse(Request request) {

        //Associa o fluxo inFile ao arquivo fileName
        if (request.getMethod().equals("GET"))
        {
            if (!request.getProtocol().equals("HTTP/1.1"))
            {
                return new VersionNotSupportedResponse();
            }
            String fileName;
            fileName = request.getUri();
            if (fileName.startsWith("/") == true )
                fileName = fileName.substring(1);

            File file = new File(WebServer.getBaseDir() + fileName);
            if (file.isDirectory())
                System.out.println("null");
            if (file.isFile()){
                return new FileResponse(file);
            }
            else
            {
                return new NotFoundResponse();
            }
        }
        else
        {
            return new BadResquestResponse();
        }
        //return new DummyResponse(request);
    }
}
